﻿using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using MS.InformationManagement.Support;
using MS.InformationManagement.Presenter.Support;
using MS.InformationManagement.Presenter.AnulacionRadicado;
using MS.InformationManagement.Support.Constants;
using MS.InformationManagement.Presenter.CancelShipping;

namespace MS.InformationManagement.WP.Layouts.MS.InformationManagement.WP
{
    public partial class CancelShipping : LayoutsPageBase, ICancelShippingView
    {
        #region fields

        private CancelShippingPresenter _presenter;

        #endregion

        #region Properties

        public string Motivo { get; set; }
        public bool Result { get; set; }
        public int CurrentId
        {
            get
            {
                if (string.IsNullOrEmpty(Page.Request.QueryString["ID"]))
                    return 0;
                else
                    return int.Parse(Page.Request.QueryString["ID"]);
            }
        }
        public int IdDevolucion
        {
            get
            {
                if (string.IsNullOrEmpty(Page.Request.QueryString["IdDevolucion"]))
                    return 0;
                else
                    return int.Parse(Page.Request.QueryString["IdDevolucion"]);
            }
        }
        public string CurrentListId
        {
            get
            {
                if (string.IsNullOrEmpty(Page.Request.QueryString["List"]))
                    return null;
                else
                    return Page.Request.QueryString["List"];
            }
        }

        #endregion

        #region Form Events

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            btnCancelarAccion.Click += new EventHandler(btnCancelarAccion_Click);
            btnCancelarEnvio.Click += new EventHandler(btnCancelarEnvio_Click);

            txtObservaciones.Required(ExceptionConstants.ERROR_CAMPO_NULO, "ValBtnEnviar", AjaxControlToolkit.ValidatorCalloutPosition.BottomRight);


        }

        void btnCancelarEnvio_Click(object sender, EventArgs e)
        {
            Motivo = txtObservaciones.Text;
            _presenter.CancelShipping();
        }

        void btnCancelarAccion_Click(object sender, EventArgs e)
        {
            this.CloseWindow();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            _presenter = new CancelShippingPresenter(this);
        }

        #endregion

        #region Implemented Methods

        public void Success()
        {
            if (Result == true)
            {
                this._ShowAlertAndClose("Su solicitud de envío ha sido cancelada");
            }
            else
            {
                btnCancelarAccion.Enabled = false;
                btnCancelarEnvio.Enabled = false;
                this._ShowAlertAndClose("Ha ocurrido un error.");
            }

        }

        #endregion
    }
}
